package coml.jiyun.hp.wanandroid.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import coml.jiyun.hp.wanandroid.R;
import coml.jiyun.hp.wanandroid.base.BaseLazyFragment;
import coml.jiyun.hp.wanandroid.bean.BannerBean;
import coml.jiyun.hp.wanandroid.bean.HomeBean;
import coml.jiyun.hp.wanandroid.presenter.HomePresenter;
import coml.jiyun.hp.wanandroid.ui.adapter.RlvHomeAdapter;
import coml.jiyun.hp.wanandroid.view.HomeView;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeTwoFragment extends BaseLazyFragment<HomePresenter>implements HomeView {

    @BindView(R.id.homt_Two_rlv)
    RecyclerView mRlv;
    private RlvHomeAdapter rlvHomeAdapter;

    public HomeTwoFragment() {
        // Required empty public constructor
    }

    @Override
    protected void initListener() {
    }

    @Override
    protected void initData() {
        mPresenter.getHome();
        mPresenter.getBanner();
    }

    @Override
    protected HomePresenter initPresenter() {
        return new HomePresenter();
    }

    @Override
    protected void initView(View view) {
        mRlv.setLayoutManager(new LinearLayoutManager(getActivity()));
        rlvHomeAdapter = new RlvHomeAdapter(getActivity());
        mRlv.setAdapter(rlvHomeAdapter);

    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_home_two;
    }

    @Override
    public void getHome(HomeBean homeBeane) {
        List<HomeBean.DataBean> data = homeBeane.getData();
        rlvHomeAdapter.setDataBeans(data);
        Log.d(TAG, "getHome: "+data);
    }

    @Override
    public void getBanner(BannerBean banner) {
        rlvHomeAdapter.setBannerList(banner.getData());
        rlvHomeAdapter.notifyDataSetChanged();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    private static final String TAG = "HomeTwoFragment";
}
